import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;

/*
 * PopUpGUI.java - This class associated with Notification class. When Notification class 
 * 					sends information to this class. Another frame appears on the bottom right 
 * 					of the screen and stays open 7 seconds by us-ing a new Thread. If user 
 * 					clicks to this frame, web browser opens.
 * 
 * @Author : BilCIS
 */

public class PopUpGUI extends JFrame
{	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1979837151891358387L;
	
	// Variables declaration
	private String message;
	private String header;
	// End of variables declaration
	
	public PopUpGUI( String message, String header )
	{
		this.message = message;
		this.header = header;
		create();
		this.setVisible(true);
		// mouse listener
		this.addMouseListener(new MouseListener()
		{
		    public void mouseReleased(MouseEvent e) {}
		    public void mousePressed(MouseEvent e) {}
		    public void mouseExited(MouseEvent e) {}
		    public void mouseEntered(MouseEvent e) {}
		    public void mouseClicked(MouseEvent e) 
		    {
		    	try {
					java.awt.Desktop.getDesktop().browse(java.net.URI.create("http://gmail.com"));
				} catch (IOException e1) {
					e1.printStackTrace();
				}
		    }
		});
		this.addMouseMotionListener(new MouseMotionListener()
		{
		    public void mouseMoved(MouseEvent e) {}
		    public void mouseDragged(MouseEvent e) {}
		});
		// new Thread
		new Thread(){
		      @Override
		      public void run() 
		      {
		           try 
		           {
		                  Thread.sleep(7000); // time after which pop up will be disappeared.
		                  dispose(); // disposes the frame
		           } catch (InterruptedException e) 
		           {
		                  e.printStackTrace();
		           }
		      };
		}.start();
	}

	private void create()
	{
		//
		//Create controls
		//
		JPanel contentPane = new JPanel(null);
		JLabel headerlbl = new JLabel(header);
		JTextArea messagelbl = new JTextArea(message);
		//
		//Add controls to pane
		//
		this.add(contentPane);
		contentPane.add(headerlbl);
		contentPane.add(messagelbl);
		//	
		//Set bounds
		//	
		contentPane.setBounds(this.getBounds());
		headerlbl.setBounds(10,10,300,48);
		messagelbl.setBounds(10,60,300,77);
		//
		//	header
		//
		headerlbl.setIcon(new ImageIcon( new File("mail.png").getAbsolutePath() )); 
		headerlbl.setOpaque(false);
		headerlbl.setFont(new Font("Comic Sans MS", Font.BOLD, 19));
		messagelbl.setFont(new Font("Comic Sans MS", Font.BOLD, 14));
		messagelbl.setEditable(false);
		messagelbl.setBackground(this.getBackground());
		//
		// PopUpGUI
		//
		this.setSize(300,125);	
		this.setUndecorated(true);
		this.setAlwaysOnTop(true);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.setLocation(Toolkit.getDefaultToolkit().getScreenSize().width - getWidth(),
						 Toolkit.getDefaultToolkit().getScreenSize().height - getHeight() - 50);
	}
}
